#include <iostream>
using std::cout;
using std::endl;

int add(int a, int b){
    return a + b;
}
int sub(int a, int b){
    return a - b;
}
int multiply(int a, int b){
    return a * b;
}
int divide(int a, int b){
    return a / b;
}

//根据operation的值，进而调用不同的函数
int calc(int leftNumber, const char * operation, int rightNumber){
    int (*pFunc)(int,int);
    if(operation == "+"){
        pFunc = add;
    }else if(operation == "-"){
        pFunc = sub;
    }else if(operation == "*"){
        pFunc = multiply;
    }else if(operation == "/"){
        pFunc = divide;
    }
    return pFunc(leftNumber, rightNumber);
}

int main()
{
    cout << calc(20, "+", 10) << endl;
    cout << calc(20, "-", 10) << endl;
    cout << calc(20, "*", 10) << endl;
    cout << calc(20, "/", 10) << endl;
    return 0;
}

